package com.zh.ssmshirofreemarker.Utils;

public class ResponseUtil {

    public static final int SUCCESS_CODE = 1;
    public static final int FAIL_CODE = 0;
    public static final String SUCCESS_STR = "success";
    public static final String FAIL_STR = "fail";

    private int code;    //1.成功 。 0.失败 。
    private String msg;
    private Object data;

    public ResponseUtil(int code,String msg,Object data){
       this.code = code;
       this.msg = msg;
       this.data = data;
    }

    public ResponseUtil(){

    }

    public static ResponseUtil success(Object data){
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMsg("success");
        responseUtil.setCode(1);
        responseUtil.setData(data);
        return responseUtil;
    }

    public static ResponseUtil fail(Object data){
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMsg("fail");
        responseUtil.setCode(0);
        responseUtil.setData(data);
        return responseUtil;
    }

    public static ResponseUtil fail(Object data,String msg){
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMsg(msg);
        responseUtil.setCode(0);
        responseUtil.setData(data);
        return responseUtil;
    }

    public static ResponseUtil check(boolean result){
        ResponseUtil responseUtil = new ResponseUtil();
        if(result){
            responseUtil.setMsg("success");
            responseUtil.setCode(1);
        } else{
            responseUtil.setMsg("fail");
            responseUtil.setCode(0);
        }
        responseUtil.setData(result);
        return responseUtil;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
